
function startPreferences() {
    document.getElementById('prefsframe').className = '';
    $('#prefsframe').Draggable({zIndex: 200});
    $('#prefsframe').fadeIn('600');
}

function prefs_change_effect(chkbox)
{
	if (chkbox.checked)
		ChatMessage("/" + chkbox.value + "on");
	else
		ChatMessage("/" + chkbox.value + "off");
}

function prefs_close() {
    $('#prefsframe').className = 'hidden';
    $('#prefsframe').fadeOut(200);
}

function prefs_change_skin(skin) {
	//alert(skin);
	changeSkin(skin);
}

function prefs_parse(prefs) {
	effects = document.preferences.effects;
	var prefArray = prefs.split(",");
	for (var i = 0; i < effects.length; i++) {
		for (var j = 0; j < prefArray.length; j++) {
			var prefDetails = prefArray[j].split(":");
			if (effects[i].value == prefDetails[0]) {
				if (prefDetails[1]=="0")
					effects[i].checked=false;
				else
					effects[i].checked=true;
			}
			if (prefDetails[0]=='skin') {
				changeSkin(prefDetails[1]);
				box = document.preferences.skin;
				for (x=0;x<box.length;x++)
					if (box.options[x].value==prefDetails[1])
						box.selectedIndex=x;
			}
		}
		
		
		
		if (effects[i].checked)
			ChatMessage("/" + effects[i].value + "on");
		else
			ChatMessage("/" + effects[i].value + "off");
	}
}

function prefs_save() {
	var prefs = '';
	effects = document.preferences.effects;

	for (var i = 0; i < effects.length; i++) {
		if (i > 0) prefs += ',';
		
		prefs += effects[i].value + ':';
		
		if (effects[i].checked) prefs += 1;
		else prefs += 0;
	}
	
	skin = 'default';
	if (document.preferences.skin.value != '') skin = document.preferences.skin.value;
	prefs += ',skin:' + skin;
	
	//alert(skin);
	Tracker.savePreferences(prefs);
	prefs_close();
}
